import { reactive, ref } from "vue";

export const teacher_query = reactive({
    id: "",
    name: "",
    jobTitle: "",
    skilledField: "",
})

export interface TeacherData {
    account: string,
    createTime: string,
    deleted: boolean,
    email: string,
    id: number,
    jobTitle: string,
    name: string,
    password: string,
    skilledField: string,
    telephone: string,
    updateTime: string,
}

interface PageData {
    page: number,
    count: number,
    pagesize: number,
}

export class TeacherListData {
    selectData: PageData = {
        page: 1,
        count: 0,
        pagesize: 5
    }
    TeacherList: TeacherData[] = []
}

export const Teacher = ref({
    email: "",
    jobTitle: "",
    name: "",
    skilledField: "",
    telephone: "",
})

const validateTel = (rule:any, value:any, callback:any) => {
    const reg = /^((13[0-9])|(14[5-7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/;
    if (reg.test(value)){
        callback();
    } else{
        callback(new Error("手机号码格式不匹配，请输入正确手机号格式"))
    }
}

export const TeacherRules = ref({
    email: [
        {
            type: "email",
            message: "邮箱格式不正确",
            required: true,
            trigger: 'blur',
        },
    ],

    jobTitle: [
        {
            required: true,
            message: "请输入工作主题",
            trigger: 'blur',
        },
    ],

    name: [
        {
            required: true,
            message: "请输入讲师姓名",
            trigger: 'blur',
        },
    ],

    skilledField: [
        {
            required: true,
            message: "请输入技能领域",
            trigger: 'blur',
        },
    ],

    telephone: [
        {
            required: true,
            message: "请输入手机号",
            trigger: 'blur',
        },
        {
            validator: validateTel,
            trigger: 'blur'
        },
    ],
})